package org.csu.mypetstore.web.servlets;

import org.csu.mypetstore.domain.Account;
import org.csu.mypetstore.service.LogService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "SignOffServlet", value = "/SignOffServlet")
public class SignOffServlet extends HttpServlet {
    private static final String MAIN = "/WEB-INF/jsp/catalog/main.jsp";
    private LogService logService = new LogService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        Account accountTemp =(Account) session.getAttribute("account");

        if(accountTemp!=null){
            String logInfo = logService.logInfo(" ") + " 用户登出";
            logService.insertLogInfo(accountTemp.getUsername(), logInfo);

        }

        accountTemp = null;
        session.setAttribute("account",accountTemp);



        request.getRequestDispatcher(MAIN).forward(request,response);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }
}
